#include<bits/stdc++.h>
using namespace std;
int t,ans,o[1000005],cnt=0;
struct S{
	int n,m,l,u;
	int d[100005],v[100005],a[100005],b[100005];
}s[30];
int read(){
	int r=0,f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-') f=-1;ch=getchar();}
	while(isdigit(ch)){r=(r<<3)+(r<<1)+ch-'0';ch=getchar();}
	return r*f;
}
void w(int x){
	if(x<0){
		putchar('-');
		x=-x;
	}
	if(x>=10){
		w(x/10);
	}
	putchar('0'+x%10);
}
int main(){
	freopen("detect.in","r",stdin);
	freopen("detect.out","w",stdout);
	t=read();
	for(int i=1;i<=t;i++){
		s[i].n=read();s[i].m=read();s[i].l=read();s[i].u=read();
		for(int j=1;j<=s[i].n;j++){
			s[i].d[j]=read();s[i].v[j]=read();s[i].a[j]=read();
		}
		for(int j=1;j<=s[i].m;j++){
			s[i].b[j]=read();
		}
	}
	for(int i=1;i<=t;i++){
		o[0]=0;
		for(int j=1;j<=s[i].m;j++){
			o[s[i].b[j]]=j;
		}
		for(int j=1;j<=s[i].b[s[i].m];j++){
			if(o[j]==0){
				o[j]=o[j-1];
			}
		}
		for(int j=s[i].b[s[i].m]+1;j<=1000005;j++){
			o[j]=s[i].m+1;
		}
		for(int j=1;j<=s[i].n;j++){
			if(s[i].d[j]>s[i].b[s[i].m]){
				continue;
			}
			if(s[i].a[j]==0){
				cnt=s[i].m-1;
				if(s[i].v[j]>s[i].u){
					ans++;
				}
			}
			else{
				if(s[i].a[j]<0){
					if(s[i].v[j]<=s[i].u){
						continue;
					}
					else{
						int ha=pow(s[i].v[j],2)-pow(s[i].u,2);
						int hb=2*(-s[i].a[j]);
						int q1=floor(ha/hb);
						if(o[q1+s[i].d[j]]!=o[s[i].d[j]]){
							ans++;
						}
					}
				}
				else{
					if(s[i].a[j]>0){
						cnt=s[i].m-1;
						if(s[i].v[j]>s[i].u){
							ans++;
						}
						else{
							int hc=pow(s[i].u,2)-pow(s[i].v[j],2);
							int hd=2*s[i].a[j];
							int q2=ceil(hc/hd);
							if(q2+s[i].d[j]<s[i].b[s[i].m]){
								ans++;
							}
						}
					}
				}
				
			}
			
		}
		if(ans==0){
			cnt++;
		}
		w(ans);
		ans=0;
		putchar(' ');
		w(cnt);
		putchar('\n');
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}
